<?php
/*
+--------------------------------------------------------------------------
|   phpBIZ v3.0  full version
|   ========================================
|   by taft@wjl.cn yejun@wjl.cn
|   http://www.phpbiz.cn http://www.wjl.cn
|   all rights reserved
+---------------------------------------------------------------------------
|
|   > 最后修改日期：2005-4-30 2006-2-8
|
+--------------------------------------------------------------------------
*/
!class_exists('Debug') && exit('Forbidden');
$idx = new Diyc;
class Diyc
{
	function Diyc()
	{
		global $BIZ,$INCOME,$CONF,$_LEVEL;
		
		$this -> upload_dir = stripslashes($CONF['upload_dir']);
		$this -> seller_data = new manager($BIZ->seller['seller_id']);

		//---------------------------------------
		// Kill globals - globals bad, Homer good.
		//---------------------------------------
		
		$tmp_in = array_merge( $_GET, $_POST, $_COOKIE );
		
		foreach ( $tmp_in as $k => $v )	unset($$k);
		
	    //--------------------------------------------
        // Check viewing permissions, etc
	    //--------------------------------------------
						
		if ( empty($BIZ->seller['seller_id']) or $BIZ->seller['seller_id']=="" or $BIZ->seller['seller_id']==0 )
		{
			$BIZ->error( "用户没有登陆，不能使用此功能","?act=Login&code=00" );
		}
		if( !$this -> seller_data->check($INCOME[act]) )
            $BIZ -> error("该等级用户不享有该功能。");

	    if( $BIZ->seller['seller_check_status']=='uncheck' )
		{
			$this -> seller_data-> control_panel("nocharge");
		}elseif( ($data=$this -> seller_data->get_seller_data("end_time,property_id"))&& $data['end_time']<time()&&$_LEVEL[$data['property_id']][1]>0 )
		{
			$this -> seller_data-> control_panel("due");
		}else
		{
			$BIZ -> assign('code',$INCOME['code']);
			$BIZ-> nav_link[] =array ("商家控制台","index.php?act=Promote");
			switch($INCOME['code'])
			{
				case '00':     // display general seller info
				   $this -> seller_data-> control_panel();
				   break;
				case '24':
					$BIZ-> nav_link[] = array("自定义分类","");
					$this -> catalog_form();
					break;
				case '25':
					$this -> add_custom_catalog();
				    break;
				case '26':
					$BIZ-> nav_link[] = array("修改自定义分类");
					$this -> modify_custom_catalog();
				  break;
				case '27':
					$this -> do_modify_custom_catalog();
				   break;
				case '35':
					$this -> del_cc();       //删除自定义分类，以及下面的商品
				    break;
				case '36':
					$this -> mov_cc();
				    break;
				default:
				  $this -> seller_data-> control_panel();
			}
		}
		$BIZ -> output('Diyc.tpl');
	}
	function catalog_form()
	{//24
       global $BIZ,$DB,$INCOME;

	   $DB -> db_query( "SELECT * FROM biz_shop WHERE seller_id ='".$BIZ->seller['seller_id']."'" );
       while( $r = $DB -> db_fetch_row() )
		{
		   $shop_id[] =  $r['shop_id'];
		   $shop_name[] = $r['shop_name'];
		}
		$BIZ -> assign("shop_id",$shop_id);
		$BIZ -> assign("shop_name",$shop_name);

		$DB -> db_query("SELECT c.*,s.shop_name FROM biz_custom_catalog AS c LEFT JOIN biz_shop AS s ON c.shop_id = s.shop_id WHERE c.seller_id=".$BIZ->seller[seller_id]." ORDER BY c.shop_id");

		while( $r = $DB -> db_fetch_row() )
		{
			$cd[] = array($r['id'],$r['title'],$r['shop_name']);
		}
		$BIZ -> assign("cd",$cd);
	}

	function add_custom_catalog()
	{//25
		global $BIZ,$DB,$INCOME;
		$cc = $INCOME[cc];
		if(!$cc[title])
			$BIZ -> error("错误：分类名不能为空！");
		$cc['seller_id']=$BIZ -> seller['seller_id'];
		$DB -> db_form_insert("biz_custom_catalog ",$cc);
		$BIZ ->redirect_screen("恭喜！您已经成功添加了商品分类","?act=Diyc&code=24");
	
	}

	function modify_custom_catalog()
	{//26
		global $BIZ,$DB,$INCOME;

		$id = intval($INCOME[CID]);
	    $DB -> db_query( "SELECT * FROM biz_custom_catalog WHERE id = ".$id." LIMIT 1");
        $cc = $DB -> db_fetch_row();
		

	   $DB -> db_query( "SELECT * FROM biz_shop WHERE seller_id ='".$BIZ->seller['seller_id']."'" );
       while( $r = $DB -> db_fetch_row() )
		{
		   $shop_id[] =  $r['shop_id'];
		   $shop_name[] = $r['shop_name'];
		}
		$BIZ -> assign("shop_id",$shop_id);
		$BIZ -> assign("shop_name",$shop_name);$BIZ -> assign("cc",$cc);
		
	}

	function do_modify_custom_catalog()
	{//27
	     global $INCOME,$BIZ,$DB;

		 $cid = intval($INCOME['CID']);
		 $cc = $INCOME['cc'];
         $DB -> db_form_update("biz_custom_catalog ",$cc,"id=".$cid);
         $BIZ ->redirect_screen("恭喜！您已经成功更新了自定义分类","?act=Diyc&code=24");	

	}
	function del_cc()
	{//35
	    global $DB,$BIZ,$INCOME;
        
		$cid = $INCOME['CID'];
        //unlink goods
		$DB -> db_query(" UPDATE biz_goods SET goods_ccat_id =0 WHERE goods_ccat_id =".$cid);
		//del
		$DB-> db_query(" DELETE FROM biz_custom_catalog WHERE id =".$cid);
        $BIZ ->redirect_screen("恭喜！您已经成功删除了一个自定义分类，其商品目前状态是未分类","?act=Diyc&code=24");	

	}

	function mov_cc()
	{

	}
}
?>